package org.elucid.chess.model;

import java.util.ArrayList;
import java.util.List;

/**
 * 
 * @author george
 *
 */
public abstract class Piece {

    protected final boolean isWhite;
    protected List<Square> moveHistory = new ArrayList<Square>();

    /**
     * 
     * @param isWhite
     */
    public Piece(boolean isWhite) {
        this.isWhite = isWhite;

    }

    public boolean isWhite() {
        return isWhite;
    }

    @Override
    public String toString() {
        return String.format("%s %s", (isWhite ? "White" : "Black"), this.getClass().getSimpleName());
    }

    public abstract List<Move> listLegalMoves(Game game, boolean isOnlyThreats);

	public void setMoveHistory(List<Square> moveHistory) {
		this.moveHistory = moveHistory;
	}

	public List<Square> getMoveHistory() {
		return moveHistory;
	}
	
	protected boolean isOpponentsPiece(Piece piece) {
		return piece.isWhite != this.isWhite;
	}
	
	/**
	protected void addIfEmptyOrCapture(Square fromSquare, Square toSquare, Game game, List<Move> moveList, boolean mustCapture) {
		if (toSquare != null) {
			Piece piece = game.getPieceSquares().getKey(toSquare);
			if( piece == null && mustCapture )
			{
				// do nothing
			}
			else if (toSquare != null && (piece == null || (piece.isWhite != this.isWhite && !(piece instanceof King))))
			{
				Move move = new Move(fromSquare, toSquare, piece!=null );
				moveList.add(move);
			}
		}
	}*/
}
